package com.scau.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * 配置资源路径
 */
@Configuration
public class MyMvcConfig extends WebMvcConfigurationSupport {

    @Value("${web.upload-path}")
    private String fileprefix;
    @Value("${web.menu-pic-path}")
    private String imagesPrefix;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        super.addResourceHandlers(registry);
        //获取本地图片
        registry.addResourceHandler("/uploads/**").addResourceLocations(
                "file:"+fileprefix);
        registry.addResourceHandler("/images/**").addResourceLocations(
                "file:"+imagesPrefix);

        //因上，所以需要配置资源位置
        registry.addResourceHandler("/layui/**").addResourceLocations(
                ResourceUtils.CLASSPATH_URL_PREFIX + "/static/layui/");
        registry.addResourceHandler("/js/**").addResourceLocations(
                ResourceUtils.CLASSPATH_URL_PREFIX + "/static/js/");
        registry.addResourceHandler("/echarts/**").addResourceLocations(
                ResourceUtils.CLASSPATH_URL_PREFIX + "/static/echarts/");
    }

}
